// components/typesCard/index.js
const api = require('../../utils/request.js') 
Component({
  options: {
    addGlobalClass: true
  },
  /**
   * 组件的属性列表
   */
  properties: {
    typeId: {
      type: Number,
      value: null
    },
    name: {
      type: String,
      value: ''
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    childs: []
  },

  lifetimes: {
    attached () {
      if (this.data.typeId) {
        this.getChildList()
      }
    }
  },
  /**
   * 组件的方法列表
   */
  methods: {
    getChildList() {
      return new Promise(resolve => {
        api._get('/Mall/GoodsType/List', {
          fatherID: this.data.typeId
        }, {
          loading: false
        }).then(res => {
          if (res.Code === 100000) {
            this.setData({
              childs: res.Data
            })
            resolve()
          }
        })
      })
    }
  }
})
